<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;
use think\Collection;

/**
 * Class MemberDraft
 * @package app\model
 * @property int $id
 * @property int $subType
 * @property int $memberId
 * @property int $checkStatus
 * @property string $checkCause
 * @property string $realname
 * @property int $provinceId
 * @property int $cityId
 * @property string $practiceNumber
 * @property string $practicingLawFirm
 * @property string $certificatePic
 * @property int $practiceTime
 * @property string $headImgUrl
 * @property string $cropImgUrl
 * @property string $introduce
 * @property string $lawFirmAdd
 * @property string $chargingStandard
 * @property int $updated
 * @property int $created
 * @property string $certificatePicImg
 * @property Member $member
 * @property Collection $categories
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class MemberDraft extends BaseModel
{
    protected $name = 'MemberDraft';

    public function member()
    {
        return $this->belongsTo(Member::class, 'memberId', 'id');
    }

    public function province()
    {
        return $this->hasOne(Area::class, 'id', 'provinceId');
    }

    public function city()
    {
        return $this->hasOne(Area::class, 'id', 'cityId');
    }

    // 擅长领域
    public function categories()
    {
        return $this->belongsToMany(LawCaseCategory::class, MemberDraftCategoryRel::class, 'categoryId', 'memberDraftId');
    }

    // 身份证图片
    public function getIdcardPicImgAttr($value, $data)
    {
        return image_url($data['idcardPic'] ?? '');
    }

    // 身份证图片2
    public function getIdcard2PicImgAttr($value, $data)
    {
        return image_url($data['idcard2Pic'] ?? '');
    }

    // 证书图片
    public function getCertificatePicImgAttr($value, $data)
    {
        return image_url($data['certificatePic'] ?? '');
    }

    // 头像
    public function getHeadImgAttr($value, $data)
    {
        return image_url($data['headImgUrl'] ?? '');
    }

    // 裁剪后头像
    public function getCropImgAttr($value, $data)
    {
        return image_url($data['cropImgUrl'] ?? '');
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'MemberDraft表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'MemberDraft表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中MemberDraft的键');
    //    }
}
